package com.wanglianyun.service.impl;

import com.wanglianyun.service.RedissonClientApi;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Description:
 * Copyright: Copyright (c) 2024
 * Create Time: 2024-11-12 16:42
 *
 * @author wanglianyun
 */
@Service
public class RedissonClientApiImpl implements RedissonClientApi {

    private static final String LOCK_KEY = "stock_lock:";

//    @Resource
//    RedissonClient redissonClient;

    @Override
    public boolean deductStockWithRedisson(String productId) {
//        RLock lock = redissonClient.getLock(LOCK_KEY + productId);
//        try {
//            //尝试上锁（分布式锁）
//            lock.lock();
//            System.out.println("redisson上锁成功，执行库存扣减业务操作");
//            return true;
//        } finally {
//            // 释放分布式锁
//            lock.unlock();
//        }

        return false;
    }
}
